package com.example.controller;

import com.example.common.result.Result;
import com.example.entity.vo.AttendanceVo;
import com.example.entity.vo.DeviceProgressVo;
import com.example.entity.vo.DeviceRateVo;
import com.example.entity.vo.DeviceSatusVo;
import com.example.service.DeviceService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/api/device")
@Api(tags = "设备报表相关接口")
public class DeviceController {


    @Autowired
    private DeviceService deviceService;

    /**
     * 查看设备运行中、闲置、其他占比
     */
    @ApiOperation("查看设备占比")
    @GetMapping("/rate")
    public Result<DeviceRateVo> getCheck(){
        DeviceRateVo deviceRateVo =deviceService.getDeviceRate();
        return Result.ok(deviceRateVo);
    }

    @ApiOperation("查看设备状态")
    @GetMapping("/Status")
    public Result<List<DeviceSatusVo>> getDeviceStatus() {
        List<DeviceSatusVo> list =deviceService.getDeviceStatus();
        return Result.ok(list);
    }
    //当日生产量
//    @ApiOperation("查看当日生产量")
//    @GetMapping("/output")
//    public Result<OutputVo> getOutput(){
//        OutputVo output=deviceService.getOutput();
//        return Result.ok(output);
//    }

    //机器工作任务进度
    @ApiOperation("正在加工中机器任务进度")
    @GetMapping("/progress")
    public Result<List<DeviceProgressVo>> progress(){
        List<DeviceProgressVo> list=deviceService.progress();
        return Result.ok(list);
    }

    @ApiOperation("考勤视图查询")
    @GetMapping("/attendance")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "查询类型 0:生产课、押出课视图(默认)  1:装配课视图", required=false,
                    defaultValue="0", dataType = "int"),
            @ApiImplicitParam(name = "date", value = "需要查看的日期（默认当天）(yyyy-MM-dd)", required=false,
                    dataType = "string")
    })
    public Result<List<AttendanceVo>> attendance(@RequestParam(defaultValue = "0",required = false) Integer type,
                                                 @RequestParam(required = false) String date){
        if (date==null|| date.isEmpty()) date = LocalDate.now().toString();
        return Result.ok(deviceService.attendance(type,date));
    }

//    //查看设备效率
//    @ApiOperation("查看设备效率")
//    @GetMapping("/DeviceProductivity")
//    public Result<List<ProductivityVo>> DeviceProductivity(){
//        List<ProductivityVo> list =deviceService.getProductivity();
//        return Result.ok(list);
//    }

}
